home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Examples / PPCExamples / CExamples / PPC-68K / MainApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-03  |  1.9 KB  |  89 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MainApp.c
  3.  
  4.     Contains:    The sample application for the "calling 68K code from PowerPC" demo
  5.  
  6.     Written by:    Richard Clark
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.                  2/15/94    RC        Released
  13.  
  14.     To Do:
  15. */
  16.  
  17. #include <Quickdraw.h>
  18. #include <Fonts.h>
  19. #include <Menus.h>
  20. #include <TextEdit.h>
  21. #include <Windows.h>
  22. #include <Dialogs.h>
  23. #include <OSUtils.h>
  24. #include <Resources.h>
  25. #include <SegLoad.h>
  26. #include <Events.h>
  27.  
  28. #include "WrapperTable.h"
  29. #include <MixedMode.h>
  30.  
  31. JumpTable    gCodePointers = {NULL};    // Table which contains addresses of our 68K routines
  32.  
  33. QDGlobals    qd;
  34.  
  35. main()
  36. {
  37.     Handle        ourLib;
  38.     Rect        bounds = {40, 10, 140, 210};
  39.     WindowPtr    wp;
  40.     long        result;
  41.     
  42.     // Initialize the ROM
  43.     InitGraf(&qd.thePort);
  44.     InitFonts();
  45.     InitWindows();
  46.     InitMenus();
  47.     TEInit();
  48.     InitDialogs(nil);
  49.     InitCursor();
  50.  
  51.     wp = NewWindow(NULL, &bounds, "\pDemo", true, noGrowDocProc, (WindowPtr)-1, false, 0);
  52.     if (wp) {
  53.         SetPort(wp);
  54.         MoveTo(2, 12);
  55.     } else {
  56.         SysBeep(5);
  57.         ExitToShell();
  58.     }
  59.     
  60.     // Load our library resource
  61.     ourLib = Get1IndResource('WRAP', 1);
  62.     if (ourLib) {
  63.         MoveHHi(ourLib);
  64.         HLock(ourLib);    // Lock it -- and NEVER unlock it
  65.         // Call the entry point, no parameters
  66.         CallUniversalProc((UniversalProcPtr)*ourLib, kPascalStackBased /* no result, no params */);
  67.         // Did we get the information?
  68.         if (gCodePointers.routine1) {
  69.             DrawString("\pAddress loaded");
  70.             // Just for fun -- call the routine
  71.             // N.B. Result sizes can be specified using the constants kOneByteCode through kFourByteCode, or using the
  72.             // SIZE_CODE(some item) macro
  73.         
  74.             result = CallUniversalProc(gCodePointers.routine1,
  75.                                        kPascalStackBased | RESULT_SIZE(SIZE_CODE(sizeof(short))) | STACK_ROUTINE_PARAMETER(1, kFourByteCode),
  76.                                        5L /* Here's the actual parameter */);
  77.  
  78.         } else
  79.             DrawString("\pAddress not loaded");
  80.     } else
  81.         DrawString("\pGet1IndResource failed");
  82.     
  83.     while (Button());
  84.     while (!Button());
  85.     
  86.     return 0;
  87. }
  88.  
  89.